import 'dart:math';

import 'package:star_author/config/base_configuration.dart';
import 'package:star_author/config/ui_constant.dart';
import 'package:star_author/model/backflow.dart';
import 'package:star_author/route/route_util.dart';
import 'package:star_author/utils/common_util/date_util.dart';
import 'package:star_author/utils/rouces_util.dart';
import 'package:star_author/utils/statistics/event/backflow_event.dart';
import 'package:star_author/utils/statistics/huiliu/event.dart';
import 'package:star_author/utils/statistics/huiliu/huiliu_statistics.dart';
import 'package:star_author/utils/statistics/statistics.dart';

import 'package:star_author/utils/string_util.dart';
import 'package:star_author/utils/user_util.dart';
import 'package:star_author/utils/utils.dart';
import 'package:star_author/views/products/bidder_goods_detail_page/bidder_goods_detaill_page.dart';
import 'package:star_author/views/stream/dialog/live_recording_dialog.dart';
import 'package:star_author/widgets/button_widget.dart';
import 'package:star_author/widgets/countdown/count_down_view.dart';
import 'package:star_author/widgets/custom_image/custom_image.dart';
import 'package:star_author/widgets/empty_view/v_empty_view.dart';
import 'package:star_author/widgets/visibility_detector/src/visibility_detector.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/src/extension_navigation.dart';

//价格在图片里面
//价格在图片外面
//购物车的样式
enum BiddingProductListItemStyle {
  Inside,
  Outside,
  ShopCar,
  OpeningBidder,
  Bidding,
}

//区分入口 ---详情页
enum BiddingProductListItemFormType {
  GoodDetail,
  BiddingDetail,
  Live,
  ItemCard,
}

class BiddingProductListItem extends StatefulWidget {
  final data;
  final BiddingProductListItemStyle? itemStyle;
  final BiddingProductListItemFormType? formDetail;
  final String? outsideStr;
  final Function? callback;
  final double? imageHeight;
  final double? width;

  //用于出价后返回页面 修改数据源的方法
  final Function? refreshPage;
  final bool isBoxShadow;

  const BiddingProductListItem(
    this.data, {
    Key? key,
    this.refreshPage,
    this.itemStyle = BiddingProductListItemStyle.Inside,
    this.formDetail = BiddingProductListItemFormType.BiddingDetail,
    this.outsideStr = "回款",
    this.callback,
    this.imageHeight,
    this.width,
    this.isBoxShadow = false,
  }) : super(key: key);

  @override
  State<BiddingProductListItem> createState() => _BiddingProductListItemState();
}

class _BiddingProductListItemState extends State<BiddingProductListItem> {
  Duration? countDownDuration;

  void jumpToDetail() {
    if ([BiddingProductListItemFormType.BiddingDetail]
        .contains(widget.formDetail!)) {
      BiddingProductListItemFormType formDetail =
          BiddingProductListItemFormType.GoodDetail;
      if (widget.itemStyle! == BiddingProductListItemStyle.Outside) {
        formDetail = BiddingProductListItemFormType.GoodDetail;
      } else {
        formDetail = BiddingProductListItemFormType.BiddingDetail;
      }
      Get.to(
              BidderGoodsDetailPage(
                id: widget.data['id'] ?? 0,
                formDetail: formDetail,
              ),
              preventDuplicates: false)!
          .then((value) {
        if (widget.callback != null) {
          widget.callback!();
        }
      });
    } else {}
  }

  bool get isEvaluationAgain {
    return ((widget.data['max_tender_price_from_user'] ?? "0")
            .toString()
            .isNotEmpty) &&
        (double.tryParse(widget.data['max_tender_price_from_user'] ?? "0") ??
                0) >
            0 &&
        widget.data['status'] == "evaluation";
  }

  bool isCountDown = false;
  String endTimeStr = "";

  @override
  void initState() {
    super.initState();
    endTimeStr = widget.data['expired_evaluated_at'] ?? "";

    if ((widget.data['condition_stop_time'] ?? "").toString().isNotEmpty) {
      endTimeStr = widget.data['condition_stop_time'] ?? "";
    }
    DateTime? endTime = DateUtil.getDateTime(endTimeStr);
    if (widget.itemStyle == BiddingProductListItemStyle.OpeningBidder ||
        widget.data['status'] == "evaluation") {
      countDownDuration = endTime?.difference(DateTime.now());

      int countDownSecond = countDownDuration?.inSeconds ?? 0;
      //用小时判断 后台单位为hour
      int hour = countDownDuration?.inHours ?? 0;
      if (countDownSecond > 0 &&
          hour <
              (widget.data['expired_evaluation_duration_with_count_down'] ??
                  12)) {
        isCountDown = true;
      }
    }
    if (mounted) setState(() {});
  }

  @override
  void didUpdateWidget(covariant BiddingProductListItem oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
    if (oldWidget.data != widget.data) {
      isCountDown = false;
      endTimeStr = "";
      endTimeStr = widget.data['expired_evaluated_at'] ?? "";
      if ((widget.data['condition_stop_time'] ?? "").toString().isNotEmpty) {
        endTimeStr = widget.data['condition_stop_time'] ?? "";
      }
      DateTime? endTime = DateUtil.getDateTime(endTimeStr);
      if (widget.itemStyle == BiddingProductListItemStyle.OpeningBidder ||
          widget.data['status'] == "evaluation") {
        countDownDuration = endTime?.difference(DateTime.now());

        int countDownSecond = countDownDuration?.inSeconds ?? 0;
        //用小时判断 后台单位为hour
        int hour = countDownDuration?.inHours ?? 0;
        if (countDownSecond > 0 &&
            hour <
                (widget.data['expired_evaluation_duration_with_count_down'] ??
                    12)) {
          isCountDown = true;
        }
      }
      if (mounted) setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        jumpToDetail();
      },
      child: VisibilityDetector(
        key: Key(widget.data['id'].toString()),
        onVisibilityChanged: (visibilityInfo) {
          var visiblePercentage = visibilityInfo.visibleFraction * 100;
          bool has_evaluated_again =
              widget.data['has_evaluated_again'] ?? false;
          //大于90%算曝光
          if (visiblePercentage >= 90) {
            if (widget.formDetail !=
                BiddingProductListItemFormType.GoodDetail) {
              debugPrint(
                  '曝光ID为 ${visibilityInfo.key} is ${visiblePercentage.toInt()}% visible 是否二次竞标:${has_evaluated_again}');
              StatisticsUtil.event(SystemEvent.ka_pian_bao_guang, {
                "backflow_id": widget.data['id'].toString(),
                "is_evaluation_again": has_evaluated_again.toString(),
              });
              String event = HuiLiuEvent.exposure_backflow;
              if (has_evaluated_again) {
                event = HuiLiuEvent.exposure_again_backflow;
              }
              Future.delayed(
                Duration(milliseconds: Random().nextInt(500)),
                () {
                  HuiLiuStatistics().event(event, {
                    'id': widget.data['id'].toString(),
                  });
                },
              );
            }
          }
        },
        child: Container(
          clipBehavior: Clip.hardEdge,
          decoration: BoxDecoration(
            borderRadius: GetRadius.all(8.w),
            color: Colors.white,
            boxShadow: widget.isBoxShadow
                ? [
                    BoxShadow(
                      color: Colors.black.withOpacity(0.05),
                      offset: Offset(0, 0),
                      blurRadius: 10,
                    ),
                  ]
                : null,
          ),
          child: Column(
            children: [
              Stack(
                children: [
                  Container(
                    color: Color(0xffeeeeee),
                    child: buildImage(),
                  ),
                  if (isEvaluationAgain)
                    Positioned(
                      child: Padding(
                        child: Image.asset(
                          'images/lt_backflows/return_bond.png',
                          width: 24.w,
                        ),
                        padding: EdgeInsets.all(
                          10.w,
                        ),
                      ),
                      right: 0,
                    ),
                  if (widget.data['status'] == 'evaluation')
                    Positioned(
                      top: 10.w,
                      left: 0,
                      child: buildOfferPriceText(), //已投
                    ),
                  buildBottomView(),
                ],
              ),
              if (widget.itemStyle == BiddingProductListItemStyle.Outside)
                Container(
                  alignment: Alignment.centerLeft,
                  child: Container(
                    child: RichText(
                      text: TextSpan(children: [
                        TextSpan(
                          text: '${widget.outsideStr} ￥',
                          style: TextStyle(
                            color: ColorConf.orange,
                            fontSize: 12.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        TextSpan(
                          text:
                              '${formatPrice(widget.data['immediate_discount_price'])}',
                          style: TextStyle(
                            color: ColorConf.orange,
                            fontSize: 18.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ]),
                      textAlign: TextAlign.center,
                    ),
                    alignment: Alignment.centerLeft,
                  ),
                  margin: EdgeInsets.symmetric(
                    vertical: 7.w,
                    horizontal: 5.w,
                  ),
                ),
              buildPainterWidget(),
              buildBottomColumn(),
            ],
          ),
        ),
      ),
    );
  }

  String get diamondTitle {
    String result = '';
    if (['钻石', '彩宝'].contains(widget.data['goods']['category'])) {
      String title = widget.data['goods']['title'] ?? '';
      if (title.contains('主石')) {
        result = title.substring(title.indexOf('主石'));
      }
    }

    return result;
  }

  get isPainter {
    return widget.data['goods']['category_prefix'] == 'P' &&
        widget.data['status'] == "evaluation";
  }

  buildPainterWidget() {
    if (isPainter) {
      return Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            painterWidget(),
          ],
        ),
      );
    }
    return Container();
  }

  Widget buildImage() {
    int serverWidth = widget.data['goods']['cover']['width'] ?? 1;
    int serverHeight = widget.data['goods']['cover']['height'] ?? 1;
    double itemWidth = (Get.width - 12.w - 12.w - 9.w) / 2;

    double radio = serverWidth / serverHeight;
    double resultHeight = itemWidth / radio;

    Widget tempImage = CustomImage.network(
      widget.data['goods']['cover']['url'] ?? "",
      width: itemWidth,
      height: resultHeight,
      fit: BoxFit.cover,
    );

    return widget.imageHeight != null
        ? CustomImage.network(
            widget.data['goods']['cover']['url'] ?? "",
            height: widget.imageHeight,
            width: itemWidth,
            fit: BoxFit.cover,
          )
        : tempImage;
  }

  Widget buildPriceRangeTitle() {
    return Text(
      "源头市场价 ",
      style: TextStyle(
        fontSize: 12.sp,
        color: rgba(153, 153, 153, 1),
      ),
    );
  }

  Widget buildBottomColumn() {
    BackflowModel model = BackflowModel(widget.data);
    //配件需要显示
    if (widget.data['goods']['category'] == "配件") {
      return Container(
        padding: EdgeInsets.only(
          top: 10.w,
          bottom: 12.w,
          left: 12.w,
          right: 12.w,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Text(
              ((widget.data['goods']['title'] ?? "")
                      .replaceAll(widget.data['goods']['serial'] ?? "", ""))
                  .toString()
                  .trimRight()
                  .trimLeft(),
              style: TextStyle(
                color: rgba(34, 34, 34, 1),
                fontSize: 14.sp,
              ),
            ),
            SizedBox(
              height: 10.w,
            ),
            Text(
              "¥${widget.data['confirmed_price']}",
              style: TextStyle(
                color: rgba(255, 143, 0, 1),
                fontSize: 14.5.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      );
    }
    if (widget.formDetail == BiddingProductListItemFormType.GoodDetail ||
        (widget.itemStyle == BiddingProductListItemStyle.Outside) ||
        model.status != "evaluation") {
      return Container();
    }
    //没有录播 没有评估价格 全部不显示
    if (model.priceRange.length == 0 && model.recording_video.isEmpty) {
      if (diamondTitle.isNotEmpty) {
        return Container(
          alignment: Alignment.centerLeft,
          margin: EdgeInsets.all(10.w),
          child: Text(
            diamondTitle,
            style: TextStyle(
              color: UIConstant.color33,
              fontSize: 14.sp,
            ),
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
          ),
        );
      } else {
        return Container();
      }
    }
    return Container(
      margin: EdgeInsets.only(
        left: 10.w,
        right: 10.w,
      ),
      child: Column(
        children: [
          VEmptyView(10.w),
          if (diamondTitle.isNotEmpty)
            Container(
              margin: EdgeInsets.only(
                bottom: 4.w,
              ),
              child: Text(
                diamondTitle,
                style: TextStyle(
                  color: UIConstant.color33,
                  fontSize: 14.sp,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          Container(
            margin: EdgeInsets.only(
              bottom: 10.w,
            ),
            child: Builder(builder: (context) {
              if (model.priceRange.length == 0) return Container();
              double itemWidth = ((Get.width - 12.w - 12.w - 9.w) / 2) - 20.w;
              List range = model.priceRange;
              String price_range_show_name = model.price_range_show_name;
              TextPainter _textPainter = getTextPainter(
                  context,
                  "源头市场价 :${getPriceWithList(
                    range,
                    intl: true,
                    show_name: price_range_show_name,
                  )}",
                  TextStyle(
                    fontSize: 12.sp,
                    color: rgba(153, 153, 153, 1),
                  ),
                  itemWidth,
                  1);
              Widget price_range = Text(
                "${getPriceWithList(
                  range,
                  intl: true,
                  show_name: price_range_show_name,
                )}",
                style: TextStyle(
                  fontSize: 12.sp,
                  color: rgba(240, 69, 41, 1),
                  fontWeight: FontWeight.w500,
                ),
              );
              if (_textPainter.didExceedMaxLines) {
                return Container(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      buildPriceRangeTitle(),
                      SizedBox(
                        height: 4.w,
                      ),
                      price_range,
                    ],
                  ),
                  width: itemWidth,
                );
              }
              return Container(
                child: Row(
                  children: [
                    buildPriceRangeTitle(),
                    price_range,
                  ],
                ),
                width: itemWidth,
              );
            }),
          ),
          Container(
            margin: EdgeInsets.only(
              bottom: 10.w,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Builder(builder: (context) {
                  if (model.recording_video.isEmpty) {
                    return Container();
                  }
                  return GestureDetector(
                    child: Row(
                      children: [
                        RoucesUtil.getAssetsIcon('ic_classify_live_lt', 14),
                        SizedBox(
                          width: 3.w,
                        ),
                        Text(
                          "看讲解",
                          style: TextStyle(
                            color: rgba(51, 51, 51, 1),
                            fontSize: 12.sp,
                          ),
                        ),
                      ],
                    ),
                    onTap: () {
                      StatisticsUtil.event(HomePageEvent.lie_biao_kan_lu_bo, {
                        "backflow_id": model.id.toString(),
                      });
                      LiveRecordingDialogUtil.showDialog(
                        model.recording_video,
                        0,
                        model.toJson(model),
                        liveRecordForm: LiveRecordForm.DetailNoLiving,
                      );
                    },
                    behavior: HitTestBehavior.opaque,
                  );
                }),
                Builder(builder: (context) {
                  if (model.isMine(UserUtil.getUserId(context)))
                    return Container();
                  if (model.tenderPrice?.isNotEmpty ?? false) {
                    return ButtonWidget(
                      child: Text(
                        "已出价",
                        style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500,
                          color: rgba(153, 153, 153, 1),
                        ),
                      ),
                      type: ButtonType.bgGray,
                      width: 80,
                      height: 28,
                      onPressed: () {
                        Get.to(BidderGoodsDetailPage(id: model.id));
                      },
                    );
                  }
                  return ButtonWidget(
                    child: Text(
                      "出个价",
                      style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500,
                          color: Colors.white),
                    ),
                    type: ButtonType.bgOrange,
                    width: 80,
                    height: 28,
                    onPressed: () {
                      RouteUtil.checkLogin(context, () {
                        StatisticsUtil.event(
                            HomePageEvent.lie_biao_chu_ge_jia, {
                          "backflow_id": model.id.toString(),
                        });
                        Get.to(
                          BidderGoodsDetailPage(
                            id: model.id,
                            formDetail: BiddingProductListItemFormType.ItemCard,
                            isNeedShowPriceDialog: true,
                          ),
                        )?.then((value) {
                          if (value.toString().isNotEmpty) {
                            double v = double.tryParse(value) ?? 0;
                            if (v > 0) {
                              if (widget.refreshPage != null) {
                                widget.refreshPage!(value);
                              }
                            }
                          }
                        });
                      });
                    },
                  );
                })
              ],
            ),
          ),
        ],
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
      ),
    );
  }

  Widget buildBottomView() {
    //配件不需要这个图标
    if (widget.data['goods']['category'] == "配件") return Container();

    Widget _countdownView = Positioned(
      bottom: 0,
      left: 0,
      right: 0,
      child: Container(
        height: 28.w,
        width: widget.width,
        alignment: Alignment.center,
        decoration: BoxDecoration(color: Color(0xFFF04529)),
        child: buildCountDownText(),
      ),
    );

    Widget _textView = Container();
    if (widget.data['status'] != "evaluation") {
      if (widget.data['status'] != "back") {
        _textView = Positioned(
          bottom: 10.w,
          left: 10.w,
          child: Container(
            decoration: BoxDecoration(
              color: Colors.white.withOpacity(0.9),
              borderRadius: BorderRadius.all(
                Radius.circular(1000),
              ),
            ),
            padding: EdgeInsets.symmetric(
              horizontal: 12.w,
              vertical: 6.w,
            ),
            child: buildBottomText(),
          ),
        );
      }
    } else {
      _textView = Container();
    }

    if (widget.itemStyle == BiddingProductListItemStyle.Bidding) {
      return _textView;
    } else if (widget.itemStyle == BiddingProductListItemStyle.Inside) {
      if (["onsale", "finished", "waitconfirm"]
              .contains(widget.data['status']) ||
          isCountDown == false) {
        return _textView;
      }
      return _countdownView;
    } else if (widget.itemStyle == BiddingProductListItemStyle.ShopCar) {
      return _textView;
    } else if (widget.itemStyle == BiddingProductListItemStyle.OpeningBidder) {
      return _countdownView;
    } else if (widget.itemStyle == BiddingProductListItemStyle.Outside) {
      return Container();
    }
    return Container();
  }

  Widget buildCountDownText() {
    if (isCountDown) {
      return CountdownView(
        countDownDuration!,
        Duration(seconds: 1),
        (context, remaining) {
          String content = '';
          String hour = StringUtil.toTwoDigits(remaining.inHours);

          String minute =
              StringUtil.toTwoDigits(remaining.inMinutes.remainder(60));

          String second =
              StringUtil.toTwoDigits(remaining.inSeconds.remainder(60));

          content = "$hour : $minute : $second";

          return Text(
            content,
            style: TextStyle(
              fontSize: 14.sp,
              color: Colors.white,
              fontWeight: FontWeight.w500,
            ),
          );
        },
        Text(
          '00 : 00 : 00',
          style: TextStyle(
            fontSize: 14.sp,
            color: Colors.white,
            fontWeight: FontWeight.w500,
          ),
        ),
        isStartWhenInit: true,
        onFinish: () {
          if (mounted)
            setState(() {
              isCountDown = false;
            });
        },
      );
    } else {
      return Container();
    }
  }

  painterWidget() {
    if (isPainter) {
      return Column(
        children: [
          Container(
            child: Text(
              "${(widget.data['goods']['title'] ?? "").replaceAll(widget.data['goods']['serial'] ?? "", "")}",
              style: TextStyle(
                fontSize: 14.sp,
                color: UIConstant.color33,
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
            margin: EdgeInsets.only(
              bottom: 5.w,
              top: 10.w,
              left: 2.w,
            ),
            alignment: Alignment.centerLeft,
          ),
          if (isCountDown == false)
            Container(
              alignment: Alignment.centerLeft,
              child: RichText(
                text: TextSpan(children: [
                  TextSpan(
                    text: '已有',
                    style: getStyle(ColorConf.gray),
                  ),
                  TextSpan(
                    text: " ${(widget.data['already_tenders_count'] ?? 0)} ",
                    style: getStyle(ColorConf.orange),
                  ),
                  TextSpan(
                    text: '人出价',
                    style: getStyle(ColorConf.gray),
                  ),
                ]),
              ),
              margin: EdgeInsets.only(
                bottom: 12.w,
                left: 5.w,
              ),
            ),
        ],
      );
    }
    return Container();
  }

  TextStyle getStyle(Color color) {
    return TextStyle(
      color: color,
      fontSize: 12.sp,
    );
  }

  Widget buildBottomText() {
    Map<String, Function> renderMap = {
      'waitconfirm': () {
        return RichText(
          text: TextSpan(children: [
            TextSpan(
              text: '回款价',
              style: TextStyle(
                color: ColorConf.gray,
                fontSize: 12.sp,
              ),
            ),
            TextSpan(
              text: '￥',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 14.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
            TextSpan(
              text: '${formatPrice(widget.data['immediate_discount_price'])}',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 14.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ]),
        );
      },
      'onsale': () {
        //竞标的onsale
        if (widget.formDetail == BiddingProductListItemFormType.BiddingDetail) {
          return RichText(
            text: TextSpan(children: [
              TextSpan(
                text: '回款价',
                style: TextStyle(
                  color: ColorConf.gray,
                  fontSize: 12.sp,
                ),
              ),
              TextSpan(
                text: '￥',
                style: TextStyle(
                  color: ColorConf.orange,
                  fontSize: 14.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
              TextSpan(
                text: '${formatPrice(widget.data['immediate_discount_price'])}',
                style: TextStyle(
                  color: ColorConf.orange,
                  fontSize: 14.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ]),
          );
        }
        return RichText(
          text: TextSpan(children: [
            widget.data['is_special_offer'] ?? false
                ? WidgetSpan(
                    child: Container(
                        margin: EdgeInsets.only(right: 4.w),
                        child: Image(
                          image: AssetImage('images/lt_common/hui.png'),
                          width: 18.w,
                        )),
                  )
                : widget.data['is_special_offer'] ?? false
                    ? WidgetSpan(
                        child: Container(
                            margin: EdgeInsets.only(right: 4.w),
                            child: Image(
                              image: AssetImage('images/lt_common/mygood.png'),
                              width: 18.w,
                            )),
                      )
                    : TextSpan(),
            TextSpan(
              text: '￥',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 12.w,
                fontWeight: FontWeight.bold,
              ),
            ),
            TextSpan(
              text: '${formatPrice(widget.data['confirmed_price'])}',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 18.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ]),
        );
      },
      'finished': () {
        return RichText(
          text: TextSpan(children: [
            TextSpan(
              text: '￥',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 12.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
            TextSpan(
              text: '${widget.data['immediate_discount_price']}',
              style: TextStyle(
                color: ColorConf.orange,
                fontSize: 18.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ]),
        );
      }
    };
    Function render = renderMap[widget.data['status']] ?? () => Container();
    return render();
  }

  //已有多少人出价
  Widget buildOfferPriceText() {
    return Container(
      margin: EdgeInsets.only(
        left: 10.w,
      ),
      height: 22.w,
      alignment: Alignment.center,
      padding: EdgeInsets.only(
        left: 10.w,
        right: 8.w,
      ),
      decoration: BoxDecoration(
        color: rgba(255, 255, 255, 0.9),
        borderRadius: BorderRadius.circular(12.w),
      ),
      child: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: '已有',
              style: getStyle(ColorConf.gray),
            ),
            TextSpan(
              text: "${(widget.data['already_tenders_count'] ?? 0)}",
              style: getStyle(ColorConf.orange),
            ),
            TextSpan(
              text: '人出价',
              style: getStyle(ColorConf.gray),
            ),
          ],
        ),
      ),
    );
  }
}
